//
//  ViewController.m
//  04-KVO代码研究
//
//  Created by 我演示 on 2020/8/5.
//  Copyright © 2020 Jerry-Fu. All rights reserved.
//

#import "ViewController.h"
#import "FSLPerson.h"
#import <objc/runtime.h>


@interface ViewController ()

/**<#type#>*/
@property(nonatomic,strong) FSLPerson *person;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.person = [[FSLPerson alloc] init];
//    self.person.age = 10;
    
    [self.person setValue:@20  forKey:@"age"];
    NSLog(@"person1添加KVO之前 %@",object_getClass(self.person));
   
    NSLog(@"地址%p",   [self.person methodForSelector:@selector(setAge:)]);
//   
////    给person对象添加一个KVO的监听 context 也是可以进行传递的
//    NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld ;
//    [self.person addObserver:self  forKeyPath:@"age" options:optind  context:nil ];
//    NSLog(@"person1添加KVO之后 %@", object_getClass(self.person));
//     NSLog(@"地址%p",   [self.person methodForSelector:@selector(setAge:)]);
//    
//    [self.person methodForSelector:@selector(setAge:)];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    self.person.age = 20;
    [self.person setAge: 15];
    
    
    //setValueForKey的信息内容
    
    [self.person setValue:@10  forKey:@"age"];
//    setValueForKeyPath
//    
    
}

- (void)dealloc
{
    [self.person  removeObserver:self  forKeyPath:@"age"];
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    NSLog(@"监听属性值的变换 -%@  -%@  -%@"  , object , keyPath , change);
}


-(void)didChangeValueForKey:(NSString *)key {
    
}

-(void)willChangeValueForKey:(NSString *)key {
    
}

@end
